<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>医学图书</title>
    <link href="../css/medicine_book.css" type="text/css" rel="stylesheet"/>
    <script type="application/javascript" src="../js/jquery.min副本.js"></script>
    <meta name="layoutmode" content="standard"/>
    <meta content="telephone=no" name="format-detection"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <script type="application/javascript">

        $(document).scroll(function () {
            var bannerHeight = document.getElementById("banner").offsetHeight;
            var top = $('body').scrollTop();
            if (top >= bannerHeight) {
                $('#hotWr').css({'position': 'fixed', 'top': 0, 'z-index': '9', 'width': '100%'});

                var PlaceholderDiv = $('<div id="placeholderDiv"></div>');
                if ($('#placeholderDiv').length < 1) {
                    $('#hotWr').after(PlaceholderDiv);
                }
            } else {
                $('#hotWr').css({'position': 'relative', 'top': 'auto', 'z-index': '1'});
                $('#placeholderDiv').remove();
            }
        });
    </script>
    <script type="application/javascript">

        //获取sessionKey
        function getSessionKey() {
            var url = window.location.href;
            var name = '&sessionKey=';
            var star = url.indexOf(name) + name.length;
            var end = url.indexOf('&from');

            var sessionKey = '';
            if (end != -1) {
                sessionKey = url.substring(star, end);
            } else {
                sessionKey = url.substring(star, url.length);
            }
            return sessionKey;
        }

        //数据条数
        var numRows = 0;

        $(function () {
            //当前页码
            var iNow = 0;

            //获取医生信息
//            getUserInfo();

            //初始化图书列表
            init();

            //打开类列表、遮罩层
            $('.hot_bar').click(function () {
                var over = $('<div id="over"></div>');

                if (!$('#hotList').is(':visible')) {
                    $('#hotList').show();
                    $('#menu').show();
                    if ($('#over').length < 1) {
                        $('.list').append(over);
                    }
                } else {
                    $('#hotList').hide();
                    $('#menu').hide();
                    $('#over').remove();
                }
            });

            //选择分科列表
            $('#hotList').on('click', 'li', function () {
                $('body').css('position', 'static');
                $('#hotWr').css({'position': 'relative', 'top': 'auto', 'z-index': '1'});
                $('#placeholderDiv').remove();

                var title = $(this).text();
                var className = $(this).find('i').attr('class');
                $('.hot_bar h3 span').text(title);
                $('.hot_bar h3 i').attr('class', className);

                var id = $(this).attr('data-id');

                //把当前页码改成0
                iNow = 0;

                if (id == 'hot') {
                    init();

                } else {
                    $('#bookList').html(''); //先清空列表
                    $('#classNav').attr('data-id', id);
                    getBookList(id);
                }

                $('#hotList').hide();
                $('#menu').hide();
                $('#over').remove();
            });

            //弹出弹出框
            $('#bookList').on('click', 'a', function () {
                var author = $(this).find('.author').text();
                var cnTitle = $(this).find('.name b').text();
                var coverImage = $(this).find('img').attr('src');
                var cuPrice = $(this).find('.price i').text();
                var introduce = $(this).attr('data-introduce');

                var $pop = $('#pop');
                $pop.find('img').attr('src', coverImage)
                $pop.find('.title').text(cnTitle);
                $pop.find('.summary').text(introduce);
                $pop.find('.author').text('主编：' + author);
                $pop.find('.price i').text(cuPrice);
                $pop.show();
            });

            //关闭弹出框
            $('#pop').find('.close').click(function () {
                $('#pop').hide();
            });

            //设置banner高度
            var bannerHeight;
            var oImage = new Image();
            oImage.src = $('#banner').find('img').attr('src');
            oImage.onload = function () {
                bannerHeight = $('#banner').outerHeight();
            };


//            获取下一页图书列表
            function getNextPage(n) {
                var sessionKey = getSessionKey();
                var categoryStr = $('#classNav').attr('data-id');

                var url = '';
                if ($('#classNav').attr('class') == 'k1') {
                    console.log('滚动到页数：' + n);
                    url = "http://services.xingshulin.com/EPocketServlet/JsonBookServlet?m=GetTopRecommendBook&pageIndex=" + n + "&sessionKey=" + sessionKey;
                } else {
                    url = "http://services.xingshulin.com/EPocketServlet/JsonBookServlet?m=BookListByCategoryID&pageIndex=" + n + "&categoryStr=" + categoryStr + "&sessionKey=" + sessionKey;
                }

                $.ajax({
                    type: "POST",
                    url: url,
                    data: "json",
                    success: function (data) {
                        var dataObj = eval("(" + data + ")");
                        autoBookList(dataObj);
                    },
                    error: function () {
                        alert('网络错误，请稍后再试')
                    }
                });
            }

            //选择类别置顶效果
            $(document).scroll(function () {
                //当滚动到底部的时候加载下一页
                var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
                var clientHeight = document.documentElement.clientHeight;

                var bodyHeight = document.body.scrollHeight;
                if (scrollTop >= bodyHeight - clientHeight) {
                    iPage = Math.floor(numRows / 10);
                    if (iNow < iPage) {
                        iNow++;
                        getNextPage(iNow);
                    }
                }
            });


            $(document).click(function (ev) {
                if ($('#pop').is(':visible') && !$(ev.target).parents().hasClass('pop_inner') && !$(ev.target).parents().hasClass('list')) {
                    $('#pop').hide();
                }

                if (!$(ev.target).parents().hasClass('hot_bar')) {
                    $('#hotList').hide();
                    $('#menu').hide();
                    $('#over').remove();
                }
            });

            reInit();
        });

        //判断是否是微信内打开
        function is_weixin() {
            var ua = navigator.userAgent.toLowerCase();
            if (ua.match(/MicroMessenger/i) == "micromessenger") {
                return true
            } else {
                return false;
            }
        }


        //        获取用户信息
        //        function getUserInfo() {
        //            var sessionKey = getSessionKey();
        //
        //            $.ajax({
        //                type: "POST",//请求方式
        //                url: "http://services.xingshulin.com/EPocketServlet/JsonBookServlet2?sessionKey=" + sessionKey + 'D&m=GetUserInfoBySessKey',
        //                data: "json",
        //                success: function (data) {
        //                    var dataObj = eval("(" + data + ")");
        //
        //                    if (dataObj.obj == 'LoginFalse') {
        //                        $('#banner').find('b').text('领取『医口袋』的限免图书啦');
        //                    } else {
        //                        $('#banner').find('b').text(dataObj.obj.trueName + dataObj.obj.userType + '分享『医口袋』的限免图书啦');
        //                    }
        //                },
        //                error: function () {
        //                    alert('网络错误，请稍后再试');
        //                }
        //            });
        //
        //        }


        //初始化图书列表(热门推荐)
        function init() {
            var url = window.location.href;

//            var index = url.indexOf('?');
//            var URL = url.substring(index + 1, url.length);
//            $.ajax({
//                type: "POST",//请求方式
//                url: "http://services.xingshulin.com/EPocketServlet/JsonBookServlet?" + URL,
//                data: "json",
//                success: function (data) {
//                    var dataObj = eval("(" + data + ")");
//
//                    //获取热门推荐数据总数
//                    numRows = dataObj['numRows'];
//                    if (dataObj.resultObj.errorCode == '10001') {
//                        reInit();
//                    } else {
//                        var bookList = $('#bookList');
//                        bookList.html(''); //先清空列表
//                        autoBookList(dataObj);
//                    }
//                },
//                error: function () {
//                    alert('网络错误，请稍后再试');
//                }
//            });
        }


        //获取分类图书列表
        function getBookList(categoryStr) {
//            var sessionKey = getSessionKey();

//            console.log("http://services.xingshulin.com/EPocketServlet/JsonBookServlet?m=BookListByCategoryID&pageIndex=0&categoryStr=" + categoryStr + "&sessionKey=" + sessionKey);

//            $.ajax({
//                type: "POST",
//                url: "http://services.xingshulin.com/EPocketServlet/JsonBookServlet?m=BookListByCategoryID&pageIndex=0&categoryStr=" + categoryStr + "&sessionKey=" + sessionKey,
////                url: "../json/books_info",
//                data: "json",
//                success: function (data) {
//                    var dataObj = eval("(" + data + ")");
//
//                    //获取数据总条数
//                    numRows = dataObj['numRows'];
//
//                    var bookList = $('#bookList');
//                    bookList.html(''); //先清空列表
//                    autoBookList(dataObj);
//                },
//                error: function () {
//                    alert('网络错误，请稍后再试')
//                }
//            });
        }
        function reInit() {
            $.ajax({
                type: "GET",//请求方式
//                url: "http://services.xingshulin.com/EPocketServlet/JsonBookServlet?m=GetTopRecommendBook&pageIndex=0&sessionKey=7B63373634623161383633643333653762323435633463666532643338636366307D2C7B373436393138303965343334396361666637356366333336656334653661326435383062326161367D2C7B66616C73657D2C7B307D2C7B307D2C7B61613661303866322D316339372D343863362D623238622D3662383930323666616637657D2C7B32616134393532383061383338636565386630633264646561343331366636627D2C7B323031352D30332D31312031303A35373A35347D2C7B322E382E317D2C7B696F7365706F636B65747D2C7B494F5345706F636B65745F322E382E315F696F73382E325F6950686F6E65352D327D&jsonp",
//                async:false,
                url: "../json/books_info.json",
                data: "json",
//                dataType:'jsonp',
                success: function (data) {
                    var dataObj = eval(data);
                    numRows = dataObj['numRows'];
                    var bookList = $('#bookList');
                    bookList.html(''); //先清空列表
                    autoBookList(dataObj);
                },
                error: function () {
                    alert('网络错误，请稍后再试')
                }
            });
        }


        //输出图书列表
        function autoBookList(obj) {
            var bookList = $('#bookList');
            var data = obj['obj'];

            var $li = bookList.html();
            for (var i = 0; i < data.length; i++) {
                var author = data[i]['author'];
                var cnTitle = data[i]['cnTitle'];
                var coverImage = data[i]['coverImage'];
                var orgPrice = data[i]['orgPrice'];
                var introduce = data[i]['introduce'];

                $li += '<li>' +
                        '<a href="javascript:;" data-introduce="' + introduce + '">' +
                        '<span class="price"><b>限时免费</b><i>纸书：' + orgPrice + '元</i></span>' +
                        '<span class="img"><img src="' + coverImage + '"></span>' +
                        '<span class="name"><b>' + cnTitle + '</b><i class="author">' + author + '</i></span>' +
                        '</a>' +
                        '</li>'
            }
            bookList.html($li);
        }

    </script>
</head>
<body>
<div class="banner" id="banner">
    <div>
        <div class="hi">
            <img src="../img/a.png">

            <div class="hi-info"> Hi，王晓敏邀请你来医口袋看书啦！</div>
        </div>
        <div style="margin-bottom: 4px">
            <img src="../img/F7A14A4B-CE94-4703-8213-24C907BBA155.png">
        </div>
        <div style="padding-bottom: 24px">
            <img src="../img/38BE2872-0327-4FDC-B9BB-AA924C0FED65.png">
        </div>
        <div style="padding-bottom: 34.5px">
            <a href="https://www.amazon.cn/%E4%B8%AD%E5%8D%8E%E8%84%89%E8%AF%8A%E7%9A%84%E5%A5%A5%E7%A7%98-200%E5%B9%85%E8%84%89%E5%9B%BE%E8%A7%A3%E6%9E%90-%E5%BE%90%E8%BF%AA%E5%8D%8E/dp/B002EGJFRM?ie=UTF8&camp=536&creative=3200&creativeASIN=B002EGJFRM&linkCode=as2&ref_=as_li_tf_tl&tag=viqipwu-23">
                <div class="rectangle">
                    去看书
                </div>
            </a>
        </div>
    </div>
</div>
<div id="hotWr" class="hot_wr" style="position: relative; top: auto; z-index: 1; width: 100%;">
    <div class="hot_bar">
        <span class="arr"></span>

        <h3>
            <i class="k1"></i>
            <span>热门推荐</span>
        </h3>
    </div>
    <div class="" style="display: none" id="menu">
        <ul id="hotList" class="hot_list" style="display: none;">
            <li data-id="hot"><i class="k1"></i>热门推荐</li>
            <li data-id="2,3,4,5,6,7,8,114"><i class="k2"></i>内科</li>
            <li data-id="10,11,12,13,14,15,16,17,18,19,20"><i class="k3"></i>外科</li>
            <li data-id="22,23,24"><i class="k4"></i>妇产科</li>
            <li data-id="26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42"><i class="k5"></i>儿科</li>
            <li data-id="51,204"><i class="k6"></i>其他临床科室</li>
            <li data-id="53,110,200,108"><i class="k7"></i>辅助科室</li>
            <li data-id="300,302,304,306,308,310,312,314,316,318,320,322,324,326,328,330,332,334,336,338,340"><i
                    class="k8"></i>中西医结合科
            </li>
            <li data-id="43"><i class="k9"></i>神经内科</li>
            <li data-id="44"><i class="k10"></i>肿瘤科</li>
            <li data-id="45"><i class="k11"></i>眼科</li>
            <li data-id="46"><i class="k12"></i>耳鼻咽喉头颈科</li>
            <li data-id="101"><i class="k13"></i>口腔科</li>
            <li data-id="56"><i class="k14"></i>肛肠科</li>
            <li data-id="47"><i class="k15"></i>急诊科</li>
            <li data-id="48"><i class="k16"></i>麻醉疼痛科</li>
            <li data-id="49"><i class="k17"></i>皮肤性病科</li>
            <li data-id="54"><i class="k18"></i>通用</li>
        </ul>
        <div style="box-shadow: 0 0 2.5px 0 rgba(111, 111, 111, 0.5);background: white">
            <div class="menu_footer">
                <img src="../img/895AC9C0-D914-47D9-AA83-61FB74FE5D1A.png">
            </div>
        </div>
    </div>
</div>

<div class="list">
    <ul id="bookList">
    </ul>
</div>
<div id="pop">
    <div class="pop_inner">
        <div class="close"></div>
        <div class="content">
            <div class="img"><img src=""></div>
            <div class="text">
                <p class="title"></p>

                <p class="summary"></p>

                <p class="author"></p>

                <p class="price"><i></i><span>限时免费</span></p>
            </div>
        </div>
        <div class="foot">
            <p>打开『医口袋』，免费看书吧</p>
            <!--<div class="btn"><a href="javascript:;" id="download">快速安装</a></div>-->
            <div class="btn"><a href="javascript:;">去看书</a></div>
        </div>
    </div>
</div>
</body>
</html>